<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>注册</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="css/mui.min.css" rel="stylesheet" />
		<link href="css/register.css" rel="stylesheet" />
		<style type="text/css">
			.header h1 {
				padding-left: 35px
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">注册</h1>
			<a class="mui-pull-right has btn_open mui-action-back">已有账号</a>
		</header>
		<div class="mui-content" id="app">
			<div class="header">
				<h1><span>填写注册基本信息</span></h1>
				<span class="small_title">手机号码为账号以及账户名称</span>
			</div>
			<div class="input">

				<input onblur="check(this.value)" type="number" name="" v-model="shoujihao" id="mobile" placeholder="请输入手机号" />
				<!--<input type="number" name="" id="verify" placeholder="请输入验证码" />-->

				<input type="password" name="" id="password" v-model="pass" placeholder="请输入登陆密码" />
				<input type="password" name="" id="password1" v-model="pass1" placeholder="请确认登陆密码" />
			</div>

			<div class="pact">
				<label for="pact_box">
				<input v-model="danxuan" type="checkbox" id="pact_box" value="" />
					<span class="text">已阅读 <span class="red">《注册使用协议》</span>并同意相关注册条款内容</span>
				</label>
			</div>

			<div class="footer">
				<button v-if="msg === '0'" type="button" class="mui-btn mui-btn-grey mui-btn-block btn_open">确认注册</button>
				<button id="zhuce" v-else-if="msg === '1'" type="button" class="mui-btn mui-btn-blue mui-btn-block btn_open">确认注册</button>
			</div>
		</div>
	</body>

</html>

<script src="js/mui.min.js"></script>
<script src="js/vue.js"></script>
<script type="text/javascript">
	mui.init()
	var app = new Vue({
		el: '#app',
		data: {
			msg: '0',
			pass: "",
			pass1: "",
			shoujihao: "",
			danxuan: '',
		},
		methods: {

		}
	})
//	var canshu = ;

	mui("body").on("tap", "#zhuce", zhuce);

	//提交 账号密码
	function zhuce() {
		if(xiaoyan()) {
			tijiao();
			console.log('成功提交');
		} else {
			console.log('效验失败')
		}
	}

	//上传注册信息
	function tijiao() {
		console.log(mui("#mobile")[0].value,mui("#password")[0].value);
		mui.ajax({
			url: URL + 'meGeneralUser!createGenUser',
			data: {
				data: "[{'genPhone': " + mui("#mobile")[0].value + ",'genPassword': " + mui("#password")[0].value + "}]",
			},
			dataType: 'json', //服务器返回json格式数据
			type: 'post', //HTTP请求类型
			timeout: 10000, //超时时间设置为10秒；
			success: function(data) {
				console.log(JSON.stringify(data));
				if(data.success === true) {
					mui.toast('注册成功');
					mui.back();
				}
				mui.toast(data.msg);
			},
			error: function(xhr, type, errorThrown) {
				console.log(type)
			}
		});
	}

	//检查 手机号 是否注册
	function check(num) {
		mui.ajax(URL + 'meGeneralUser!isHas', {
			data: {
				id: num,
			},
			dataType: 'json', //服务器返回json格式数据
			type: 'post', //HTTP请求类型
			timeout: 10000, //超时时间设置为10秒；
			success: function(data) {
				app.msg = data.msg;
				if(data.msg === '0') {
					mui.toast('该账号已经注册')
					mui('#mobile')[0].focus();
				}
			},
			error: function(xhr, type, errorThrown) {
				console.log(xhr)
			}
		});

	}

	//	输入框效验
	function xiaoyan() {
		var buer = true;
		if(app.pass !== app.pass1) {
			buer = false;
			mui.toast('两次输入的密码不一样');
		} else if(app.danxuan !== true) {
			mui.toast('请勾选协议');
			buer = false;
		}
		return buer
	}
</script>